package com.secondriver.url.filter;

import static org.junit.Assert.*;

import com.secondriver.url.admin.groovy.AdminServiceDao

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;

class TestAdminServiceDao {

	private static AdminServiceDao adminServiceDao;

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		def dbConfig='''url=jdbc:postgresql://localhost:5432/tomdb|user=postgres|password=postgres|driver=org.postgresql.Driver''';
		adminServiceDao=new AdminServiceDao(dbConfig);
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
		adminServiceDao=null;
	}

	@Before
	public void setUp() throws Exception {
		println('===Test Start===');
	}

	@After
	public void tearDown() throws Exception {
		println('===Test End===');
	}

	@Test
	public void testPage1() {
		def method='page';
		def params=['table':'f_url'];
		println	adminServiceDao.execute(method, params);
	}

	@Ignore
	@Test
	public void testPage2() {
		def method='page';
		def params=['table':'no_table'];
		println	adminServiceDao.execute(method, params);
	}

	@Ignore
	@Test
	public void testPage3() {
		def method='page';
		def params=[:];
		println	adminServiceDao.execute(method, params);
	}

	@Test
	public void testPage4(){
		def params=['table':'f_url_group'];
		println adminServiceDao.execute('page', params);
	}

	@Test
	public void testQuery1(){
		def method='query';
		def params=[
			table:'f_url',
			pageSize:'2',
			pageNumber:'1'
		];
		println adminServiceDao.execute(method, params);
	}

	@Test
	public void test(){
		def params=['table':'f_url_group','data':['ugid':99, 'urlid':1, 'groupid':1]];
		println adminServiceDao.execute('insert', params);
		params['data']=['pkname':'ugid', 'pkvalue':99];
		println adminServiceDao.execute('delete', params);
	}
}
